<?php
namespace app\index\controller;

use think\admin\Controller;
use Omnipay\Omnipay;

/**
 * Class Index
 * @package app\index\controller
 */
class Ali extends Controller
{


    public function pay(){
        $gateway = Omnipay::create('Alipay_AopPage');
        $gateway->setSignType('RSA2'); // 设置签名类型
        $gateway->setAppId('2021003182695515');
        $gateway->setPrivateKey('MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCFCONqyo36218ZcJWe/vAqwyZGwWLxAxbHsPPacmUi0Tl/EZMuETcNGeNHsXKIRbKE6mbZFwQxO6oaoLpp96VQeHDbcK/4wsq8TiuR/9LHvYOx8qQQpffCj3tWCq4GsyhmILpVXEtGEFymq6+4PdGRnS4urvkyPfb3IkuOPuR7l5FV45Z++LUmPzSrwBnQSGz5QgVH2IcCq34Ua8GJIc+tuPguO2YpcvmysR86b0fG/DW4omXxzSNvoWtYq3idOwdTgWx2T/vldbCR4dVpLC4d707/BGpH9rqtTlha34N7/4BllrEkStweMN108ePmAt8n9UqZifVFl6vNBBoIRqpnAgMBAAECgf8J358BTgc7lwx31uND6afphJJSrgep25DVQUzX6aWX7+9UfvltcdmkH0e/Cmx1sLaPJtZ7RjoJbWQylbtAIiEi182Ie9SToeFqGGMjctkx+d7MVjXXBnpc9kkxGZnQ5XsaGVO7Ah6UFKLLu/JOukfThtbmoBXepLqvnNv+sqxCf+E44lCPc12EIq/eUhvNgSHH4A7Ka5kzvEmBT3bdBar50vj+lsbVgYvEI+Obj7Ko7FBaYZ5cX8kckUH7TD/OJAoy2KGmLx3/FwwYctM8CDv9dM2AiKwblq0LO58bX7CMlvvvdPZreYYnL5OEVHMcAr2RScLhZjbBt3AZmdxrX0ECgYEA5i3q9ugPhRt8yYXCSQyozXtFShi+girQ0eOGrv5cdotVX4ALadyv/gXgS5n6RjgYYS/aLGVddAoQH0RBUJr8r7n0IuQ62phvqEwBc4wftt3qDVQhyGnTkVEuZpoccI0b0sUXLId+AjTLQ+eVvBVGvq0wew/NW0luxblxgqFvkgcCgYEAk/VCO0k7CBF8UCXjLWqFji0MYV6OCe5NWBtev1vLqgDQFGNAis+wY8v95H9w46F4ZQYm7C430UXdKbwWNBfvlmUxQuVpHt5xO6r8ZiJW/a/6kxIjprIzjKC4qc5MjTv3cKgHoTiXtoGEMcSFBvL0CzcDv8rxOZFOsqdCRkjAjKECgYEAnT6zLHd92r3bcsQo5MR8MNvMiwD6bGwZeblIkhV8TxOCgBo2MdyscgnLn3oSKpQ5u3L4Ran9vL7/Ioz7XbhzdQzAxnFJ73mBleROfYQ1SjSxpudZqNL60GQ4IamYUh9j6Ynw+d+Z6qHsVnhHp1SVnr8rxnYWIQ26WeMEs2vbj1MCgYAeGmptUYr3K0eVrv+3v9KIiNXaAbj4gEmwQXFXkb+wSRYM79yz4WnMBDcWBG/dgH7UXxoQN58XrxU+ZoxF8RDIErKhH7fxleSH9VQBG7+DQgjDX49tXRhr5k9sDRM6MRc5Dpbu0GrdsSBKV+eQ8GGC3qCepxXJVq0iYDF1x1uVwQKBgQCxrtkynLxbk+rYDm3eaYjLbTiUyBOagMCp+iEhsXW1f5uXQrraUeDDHCKC/TFvEFKAaKZYq19ys1dxzsO6rjiGe2d0I87SGsyqdP/wX5fj9smR73fkjMnjR/CHiiBuu8p8WaBq+I94Rygu3ZzxvGy4q1zZHga4HJGjqArzf5rF5A==');
        $gateway->setAlipayPublicKey('bum7k8dJ9OnixXesqX8CKg==');
        $gateway->setNotifyUrl('http://ai.tinyask.cn/alipaynotice');
        $gateway->setReturnUrl('http://ai.tinyask.cn/aliauth');

        // Prepare the payment request data
        // $params = [
        //     'out_trade_no' => time(), // Your order ID
        //     'total_amount' => '1', // Your order amount
        //     'subject' => '充值订单', // Your order subject
        //     'return_url' => 'http://ai.tinyask.cn/aliauth', // Your return URL after payment completed
        //     'biz_content' => json_encode(['subject' => '充值订单', 'out_trade_no' => time(), 'total_amount' => 1, 'product_code' => 12])
        // ];


        $response = $gateway->purchase()->setBizContent([
            'subject'      => 'test',
            'out_trade_no' => date('YmdHis') . mt_rand(1000, 9999),
            'total_amount' => '0.01',
            'product_code' => 'FAST_INSTANT_TRADE_PAY',
        ])->send();
        
        $url = $response->getRedirectUrl();
        // dump($url);

        // Send the payment request to Alipay
        // $response = $gateway->purchase($params)->send();

        // Redirect the user to the Alipay payment page
        $response->redirect();


    }

}